{
  class List<T> {
    pos: number = 0; // 指针
    listSize: number = 0;
    dataStore: T[] = [];

    get length(): number {
      return this.dataStore.length;
    }

    clear(): void {
      this.dataStore = [];
      this.pos = 0;
      this.listSize = 0;
    }

    toString(): string {
      return this.dataStore.map((item) => item).join('\n');
    }

    getElement(): T {
      return this.dataStore[this.pos];
    }

    insert(element: T) {
      this.dataStore.splice(this.pos, 0, element); // 数组插入
    }

    append(element: T) {
      //   this.dataStore.push(element);
      //   this.listSize++;
      this.dataStore[this.listSize++] = element;
    }

    remove(element: T): boolean {
      let index = this.find(element);
      if (index === -1) return false;
      this.dataStore.splice(index, 1);
      return true;
    }

    front() {
      if (this.pos !== 0) {
        this.exchange(this.pos, 0);
      }
    }

    end() {
      if (this.pos !== this.listSize - 1) {
        this.exchange(this.pos, this.listSize - 1);
      }
    }

    prev() {
      if (this.pos > 0) {
        this.pos--;
      }
    }

    next() {
      if (this.pos < this.listSize) {
        this.pos++;
      }
    }

    currPos(): number {
      return this.pos;
    }

    moveTo(pos: number) {
      if (pos >= 0 && !(pos > this.listSize - 1)) {
        this.pos = pos;
      }
    }

    private find(element: T): number {
      return this.dataStore.indexOf(element);
    }

    private exchange(index1: number, index2: number) {
      let temp = this.dataStore[index1];
      this.dataStore[index1] = this.dataStore[index2];
      this.dataStore[index2] = temp;
    }
  }

  let names = new List<number>();
  names.append(111);
  //   names.append('xuexue');
  //   names.append('Jack');
  //   names.append('Henry');
  console.log(names.getElement()); // jimmy
  names.next();
  console.log(names.getElement()); // jimmy
  //   names.prev();
  //   console.log(names.getElement());
  names.clear();
  console.log(names.getElement());
}
